﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows.Forms;
using QuanLiNhaSachDAO;
using QuanLiNhaSachDTO;

namespace QuanLiNhaSachBUS
{
    public class TacGiaBUS
    {
        public static DataTable getByMaSach(int MaSach)
        {
            try
            {
                return TacGiaDAO.getByMaSach(MaSach);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi khi load");
            }
            return null;
        }
        public static DataTable SelectAll()
        {
            try
            {
                return TacGiaDAO.selectAll();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi khi load");
            }
            return null;
        }

        public static void Insert(TacGia m)
        {
            try
            {
                TacGiaDAO.insert(m);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi khi thêm");
            }
        }

        public static void Update(TacGia m)
        {
            try
            {
                TacGiaDAO.update(m);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi khi chỉnh sửa");
            }
        }

        public static void Delete(string id)
        {
            try
            {
                TacGiaDAO.delete(id);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi khi xóa");
            }
        }

        public static TacGia Search(string id)
        {
            try
            {
                TacGia tl = new TacGia();
                DataTable dt = TacGiaDAO.search(id);
                tl.Id = dt.Rows[0]["id"].ToString();
                tl.Ten = dt.Rows[0]["Ten"].ToString();
                tl.Email = dt.Rows[0]["Email"].ToString();
                tl.DiaChi = dt.Rows[0]["DiaChi"].ToString();
                tl.DienThoai = dt.Rows[0]["DienThoai"].ToString();
                tl.GhiChu = dt.Rows[0]["GhiChu"].ToString();
                return tl;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi tìm kiếm");
            }
            return null;
        }
        public static DataTable TimSachTuTacGia(string id)
        {
            try
            {
                return TacGiaDAO.TimSachTuTacGia(id);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi tìm sách");
            }
            return null;
        }
    }
}
